<template>
  <el-dialog title="修改检查起止时间" :visible.sync="show" :close-on-click-modal="false" append-to-body :show-close="!btnLoading" width="600px" @closed="$refs.form.resetFields()">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item prop="rltProId" class="hide" />
      <el-form-item prop="latestTime" class="hide" />
      <el-form-item label="检查起止时间" prop="startTime">
        <el-date-picker v-model="dateRange" type="datetimerange" start-placeholder="开始时间" end-placeholder="结束时间" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%" />
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button type="primary" :loading="btnLoading" @click="btnSubmit">确 定</el-button>
      <el-button :disabled="btnLoading" @click="show = false">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
// 修改项目的检查起止时间
import { editFormMixin } from '@/utils/mixin'
import { editRltPro } from '@/api/cqPe/peRecord'
export default {
  mixins: [editFormMixin],
  data() {
    return {
      primaryKey: 'rltProId',
      updateApi: editRltPro,
      form: {
        rltProId: '',
        startTime: '',
        latestTime: ''
      },
      rules: {
        startTime: [{ required: true, message: '请选择检查起止时间' }]
      },
      dateRange: []
    }
  },
  watch: {
    dateRange: {
      immediate: true,
      handler(val) {
        const range = val || []
        this.form.startTime = range[0] || ''
        this.form.latestTime = range[1] || ''
      }
    }
  },
  methods: {
    opened(item = {}) {
      const sTime = item.startTime
      const eTime = item.latestTime
      this.dateRange = sTime && eTime ? [sTime, eTime] : []
    }
  }
}
</script>
